package online.heycm.platform.oss;

import online.heycm.platform.oss.OssProperties;
import online.heycm.platform.oss.OssService;
import online.heycm.platform.oss.OssServiceImpl;
import online.heycm.platform.oss.strategy.S3Factory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * 自动配置
 */
@ConditionalOnProperty(prefix = "oss", name = "endpoint")
@EnableConfigurationProperties(OssProperties.class)
public class OssAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(OssService.class)
    public OssService ossService(OssProperties ossProperties) {
        return new OssServiceImpl(S3Factory.createStrategy(ossProperties), ossProperties.getBucketName());
    }

}
